using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;
using WL.Think.Abp.Dto;
using WL.Think.Abp.Localization;
using WL.Think.Abp.Services;

namespace WL.Think.Abp.Controllers;

/// <summary>
/// 基础控制器
/// </summary>
[Authorize]
[ApiController]
public abstract class AppControllerBase : AbpControllerBase
{
    protected AppControllerBase()
    {
        LocalizationResource = typeof(ThinkResource);
    }
}

/// <summary>
/// 基础控制器
/// </summary>
/// <typeparam name="TAppService">业务服务</typeparam>
public abstract class AppControllerBase<TAppService> : AppControllerBase where TAppService : IThinkAppService
{
    protected AppControllerBase(TAppService appService) : base()
    {
        AppService = appService;
    }

    /// <summary>
    /// 业务服务
    /// </summary>
    protected TAppService AppService { get; }
}


/// <summary>
/// 基础控制器
/// </summary>
/// <typeparam name="TAppService">业务服务</typeparam>
/// <typeparam name="TGetOutputDto">实体对应DTO</typeparam>
/// <typeparam name="TGetListInput">分页查询DTO</typeparam>
/// <typeparam name="TCreateInput">创建实体DTO</typeparam>
/// <typeparam name="TUpdateInput">更新实体DTO</typeparam>
public abstract class AppControllerBase<TAppService, TGetOutputDto, TGetListInput, TCreateInput, TUpdateInput> :
    AppControllerBase<TAppService>
    where TAppService : IThinkAppService<TGetOutputDto, TGetListInput, TCreateInput, TUpdateInput>
    where TGetListInput : BasePagedDto
    where TCreateInput : class
    where TUpdateInput : class
{
    protected AppControllerBase(TAppService appService) : base(appService)
    {
    }


    /// <summary>
    /// 获取实体数据列表（分页）
    /// </summary>
    /// <param name="input">分页数据传输对象</param>
    /// <returns></returns>
    [HttpGet]
    public virtual Task<PagedResultDto<TGetOutputDto>> GetListAsync([FromQuery] TGetListInput input)
    {
        return AppService.GetListAsync(input);
    }


    /// <summary>
    /// 获取单个实体数据
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet("{id}")]
    public virtual Task<TGetOutputDto> GetAsync([FromRoute] Guid id)
    {
        return AppService.GetAsync(id);
    }


    /// <summary>
    /// 创建新的实体数据
    /// </summary>
    /// <param name="input">创建数据传输对象</param>
    /// <returns></returns>
    [HttpPost]
    public virtual Task<TGetOutputDto> CreateAsync([FromBody] TCreateInput input)
    {
        return AppService.CreateAsync(input);
    }


    /// <summary>
    /// 更新现有实体数据
    /// </summary>
    /// <param name="id">实体ID</param>
    /// <param name="input">更新数据传输对象</param>
    /// <returns></returns>
    [HttpPut("{id}")]
    public virtual Task<TGetOutputDto> UpdateAsync([FromRoute] Guid id, [FromBody] TUpdateInput input)
    {
        return AppService.UpdateAsync(id, input);
    }


    /// <summary>
    /// 删除实体数据
    /// </summary>
    /// <param name="id">实体ID</param>
    /// <returns></returns>
    [HttpDelete("{id}")]
    public virtual Task DeleteAsync([FromRoute] Guid id)
    {
        return AppService.DeleteAsync(id);
    }
}

/// <summary>
/// 基础控制器
/// </summary>
/// <typeparam name="TAppService">业务服务</typeparam>
/// <typeparam name="TGetOutputDto">实体对应DTO</typeparam>
/// <typeparam name="TGetListInput">分页查询DTO</typeparam>
/// <typeparam name="TCreateInput">创建实体DTO</typeparam>
public abstract class AppControllerBase<TAppService, TGetOutputDto, TGetListInput, TCreateInput> :
    AppControllerBase<TAppService, TGetOutputDto, TGetListInput, TCreateInput, TCreateInput>
    where TAppService : IThinkAppService<TGetOutputDto, TGetListInput, TCreateInput>
    where TGetListInput : BasePagedDto
    where TCreateInput : class
{
    protected AppControllerBase(TAppService appService) : base(appService)
    {
    }
}


/// <summary>
/// 基础控制器
/// </summary>
/// <typeparam name="TAppService">业务服务</typeparam>
/// <typeparam name="TGetOutputDto">实体对应DTO</typeparam>
/// <typeparam name="TGetListInput">分页查询DTO</typeparam>
public abstract class AppControllerBase<TAppService, TGetOutputDto, TCreateInput> :
    AppControllerBase<TAppService, TGetOutputDto, BasePagedDto, TCreateInput>
    where TAppService : IThinkAppService<TGetOutputDto, TCreateInput>
    where TCreateInput : class
{
    protected AppControllerBase(TAppService appService) : base(appService)
    {
    }
}

/// <summary>
/// 基础控制器
/// </summary>
/// <typeparam name="TAppService">业务服务</typeparam>
/// <typeparam name="TGetOutputDto">实体对应DTO</typeparam>
public abstract class AppControllerBase<TAppService, TGetOutputDto> :
    AppControllerBase<TAppService, TGetOutputDto, TGetOutputDto>
    where TAppService : IThinkAppService<TGetOutputDto>
    where TGetOutputDto: class
{
    protected AppControllerBase(TAppService appService) : base(appService)
    {
    }
}
